package iterator;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class IteratorDemo {
    @Test
    public void test1() {
        List<StringBuilder> list = new ArrayList<>();
        list.add(new StringBuilder("123"));
        list.add(new StringBuilder("abc"));
        list.add(new StringBuilder("+=?"));
        Iterator<StringBuilder> iterator1 = list.iterator();
        list.removeIf(e -> e.indexOf("?") != -1);
//        while (iterator1.hasNext()) {
//            StringBuilder next = iterator1.next();
//            if (next.indexOf("?") != -1) {
//                iterator1.remove();
//            }
//        }
//        iterator1.forEachRemaining(s->s.append("!!!"));
        list.forEach(System.out::println);
    }

    public void f() {
        System.out.println("f()");
    }

    class MyClass {
        void e() {
            IteratorDemo.this.f();
        }

    }

    @Test
    public void test2() {
        MyClass myClass = new MyClass();
        myClass.e();

    }
}
